package com.dq.Week2.day09.homework;

/**
 * 替换字符串的叠字
 * 例如，对于字符串 "hello nice to meet you"
 * 将其中出现两次的字符 ll 和 ee 分别替换为 l~ 和 e~
 * 输出为：hel~o nice to me~t you
 *"浩浩荡荡"
 * 输出为： 浩~荡~
 */
public class HomeWork02 {

    public static void main(String[] args) {
        String s1 = "浩浩荡荡";
        String s2 = "hello nice to meet you";
        String r1 = dealStr(s1);
        String r2 = dealStr(s2);
        System.out.println(r1);
        System.out.println(r2);
    }

    public static String dealStr(String s) {
        //将其中出现两次的字符 ll 和 ee 分别替换为 l~ 和 e~
        String regex = "(.)\\1";
//        String regex = "(\\w+)";
        s =  s.replaceAll(regex,"$1~~");

        return s;
    }


}